home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Matrix Multiplication
- Date: Sun, 28 Jan 96 01:33:32 GMT
- Organization: none
- Message-ID: <822792812snz@genesis.demon.co.uk>
- References: <1996Jan22.110440@gamma.ntu.ac.sg> <4ecjv4$fn2@tamarack.cs.mtu.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ecjv4$fn2@tamarack.cs.mtu.edu> sjang@mtu.edu "Saurabh Jang" writes:
-
- >Consider optimizing for cache performance.
- >
- >for ( i = 0; i < N; i++ )
- > for ( j = 0; j < N; j++ )
- > {
- > c[i][j] = 0.0;
- >
- > for ( k = 0; k < N; k++ )
- > {
- > c[i][j] = c[i][j] + a[i][k]*b[k][j];
- > }
- > }
-
- Or how about:
-
- for ( i = 0; i < N; i++ )
- {
- for ( j = 0; j < N; j++ )
- {
- double sum = 0.0; /* Possibly use register if it makes a difference */
-
- for ( k = 0; k < N; k++ )
- sum += a[i][k]*b[k][j];
-
- c[i][j] = sum;
- }
- }
-
- You compiler might be able to perform that optimisation for itself but
- aliasing issues may make the analysis difficult.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-